<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Class template discrete_distribution</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../boost_random/reference.html#header.boost.random.discrete_distribution_hpp" title="Header &lt;boost/random/discrete_distribution.hpp&gt;">
<link rel="prev" href="discard_block_engine.html" title="Class template discard_block_engine">
<link rel="next" href="discrete_distribution/param_type.html" title="Class param_type">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="discard_block_engine.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_random/reference.html#header.boost.random.discrete_distribution_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="discrete_distribution/param_type.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.random.discrete_distribution"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template discrete_distribution</span></h2>
<p>boost::random::discrete_distribution</p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../boost_random/reference.html#header.boost.random.discrete_distribution_hpp" title="Header &lt;boost/random/discrete_distribution.hpp&gt;">boost/random/discrete_distribution.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> IntType <span class="special">=</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">typename</span> WeightType <span class="special">=</span> <span class="keyword">double</span><span class="special">&gt;</span> 
<span class="keyword">class</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">WeightType</span> <a name="boost.random.discrete_distribution.input_type"></a><span class="identifier">input_type</span><span class="special">;</span> 
  <span class="keyword">typedef</span> <span class="identifier">IntType</span>    <a name="boost.random.discrete_distribution.result_type"></a><span class="identifier">result_type</span><span class="special">;</span>

  <span class="comment">// member classes/structs/unions</span>

  <span class="keyword">class</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">{</span>
  <span class="keyword">public</span><span class="special">:</span>
    <span class="comment">// types</span>
    <span class="keyword">typedef</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <a class="link" href="discrete_distribution/param_type.html#boost.random.discrete_distribution.param_type.distribution_type"><span class="identifier">distribution_type</span></a><span class="special">;</span>

    <span class="comment">// <a class="link" href="discrete_distribution/param_type.html#boost.random.discrete_distribution.param_typeconstruct-copy-destruct">construct/copy/destruct</a></span>
    <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_3-bb"><span class="identifier">param_type</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Iter<span class="special">&gt;</span> <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_4-bb"><span class="identifier">param_type</span></a><span class="special">(</span><span class="identifier">Iter</span><span class="special">,</span> <span class="identifier">Iter</span><span class="special">)</span><span class="special">;</span>
    <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_5-bb"><span class="identifier">param_type</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Range<span class="special">&gt;</span> <span class="keyword">explicit</span> <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_6-bb"><span class="identifier">param_type</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Range</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Func<span class="special">&gt;</span> <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_7-bb"><span class="identifier">param_type</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="identifier">Func</span><span class="special">)</span><span class="special">;</span>

    <span class="comment">// <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_2-bb">public member functions</a></span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_2_1-bb"><span class="identifier">probabilities</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

    <span class="comment">// <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_8-bb">friend functions</a></span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
      <span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
      <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_8_1-bb"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
      <span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
      <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_8_2-bb"><span class="keyword">operator</span><span class="special">&gt;&gt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">friend</span> <span class="keyword">bool</span> <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_8_3-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">friend</span> <span class="keyword">bool</span> <a class="link" href="discrete_distribution/param_type.html#id-1_3_35_5_6_10_1_1_1_3_8_4-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="special">}</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="discrete_distribution.html#boost.random.discrete_distributionconstruct-copy-destruct">construct/copy/destruct</a></span>
  <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_7-bb"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Iter<span class="special">&gt;</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_8-bb"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="identifier">Iter</span><span class="special">,</span> <span class="identifier">Iter</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_9-bb"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Range<span class="special">&gt;</span> <span class="keyword">explicit</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_10-bb"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Range</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Func<span class="special">&gt;</span> 
    <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_11-bb"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="identifier">Func</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">explicit</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_12-bb"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6-bb">public member functions</a></span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> <span class="identifier">IntType</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_1-bb"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> <span class="identifier">IntType</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_2-bb"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">result_type</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_3-bb"><span class="identifier">min</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">result_type</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_4-bb"><span class="identifier">max</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_5-bb"><span class="identifier">probabilities</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_6-bb"><span class="identifier">param</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_7-bb"><span class="identifier">param</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_6_8-bb"><span class="identifier">reset</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_13-bb">friend functions</a></span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
    <span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
    <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_13_1-bb"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> 
               <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
    <span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
    <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_13_2-bb"><span class="keyword">operator</span><span class="special">&gt;&gt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> 
               <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">friend</span> <span class="keyword">bool</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_13_3-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">,</span> 
                         <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">friend</span> <span class="keyword">bool</span> <a class="link" href="discrete_distribution.html#id-1_3_35_5_6_10_1_1_1_13_4-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">,</span> 
                         <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.35.5.6.9.3.4"></a><h2>Description</h2>
<p>The class <code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> models a <a class="link" href="../../boost_random/reference.html#boost_random.reference.concepts.random_distribution" title="Random Distribution">random distribution</a> . It produces integers in the range [0, n) with the probability of producing each value is specified by the parameters of the distribution. </p>
<div class="refsect2">
<a name="id-1.3.35.5.6.9.3.4.3"></a><h3>
<a name="boost.random.discrete_distributionconstruct-copy-destruct"></a><code class="computeroutput">discrete_distribution</code> 
        public
       construct/copy/destruct</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="id-1_3_35_5_6_10_1_1_1_7-bb"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Creates a new <code class="computeroutput"><code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code></code> object that has <span class="inlinemediaobject"><img src="../../images/random//form_4.png"></span> and <span class="inlinemediaobject"><img src="../../images/random//form_5.png"></span>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Iter<span class="special">&gt;</span> <a name="id-1_3_35_5_6_10_1_1_1_8-bb"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="identifier">Iter</span> first<span class="special">,</span> <span class="identifier">Iter</span> last<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> from an iterator range. If <code class="computeroutput">first</code> == <code class="computeroutput">last</code>, equivalent to the default constructor. Otherwise, the values of the range represent weights for the possible values of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="id-1_3_35_5_6_10_1_1_1_9-bb"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> wl<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <code class="computeroutput"><code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code></code> from a <code class="computeroutput">std::initializer_list</code>. If the <code class="computeroutput">initializer_list</code> is empty, equivalent to the default constructor. Otherwise, the values of the <code class="computeroutput">initializer_list</code> represent weights for the possible values of the distribution. For example, given the distribution</p>
<pre class="programlisting"><span class="identifier">discrete_distribution</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="identifier">dist</span><span class="special">{</span><span class="number">1</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">5</span><span class="special">}</span><span class="special">;</span>
</pre>
<p>The probability of a 0 is 1/10, the probability of a 1 is 2/5, the probability of a 2 is 1/2, and no other values are possible. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Range<span class="special">&gt;</span> <span class="keyword">explicit</span> <a name="id-1_3_35_5_6_10_1_1_1_10-bb"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Range</span> <span class="special">&amp;</span> range<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> from a Boost.Range range. If the range is empty, equivalent to the default constructor. Otherwise, the values of the range represent weights for the possible values of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Func<span class="special">&gt;</span> 
  <a name="id-1_3_35_5_6_10_1_1_1_11-bb"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> nw<span class="special">,</span> <span class="keyword">double</span> xmin<span class="special">,</span> <span class="keyword">double</span> xmax<span class="special">,</span> <span class="identifier">Func</span> fw<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> that approximates a function. If nw is zero, equivalent to the default constructor. Otherwise, the range of the distribution is [0, nw), and the weights are found by calling fw with values evenly distributed between <span class="inlinemediaobject"><img src="../../images/random//form_6.png"></span> and <span class="inlinemediaobject"><img src="../../images/random//form_7.png"></span>, where <span class="inlinemediaobject"><img src="../../images/random//form_8.png"></span>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">explicit</span> <a name="id-1_3_35_5_6_10_1_1_1_12-bb"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span> param<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> from its parameters. </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.35.5.6.9.3.4.4"></a><h3>
<a name="id-1_3_35_5_6_10_1_1_1_6-bb"></a><code class="computeroutput">discrete_distribution</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> <span class="identifier">IntType</span> <a name="id-1_3_35_5_6_10_1_1_1_6_1-bb"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span> urng<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns a value distributed according to the parameters of the <code class="computeroutput"><a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> 
  <span class="identifier">IntType</span> <a name="id-1_3_35_5_6_10_1_1_1_6_2-bb"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span> urng<span class="special">,</span> <span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span> param<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns a value distributed according to the parameters specified by param. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">result_type</span> <a name="id-1_3_35_5_6_10_1_1_1_6_3-bb"></a><span class="identifier">min</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the smallest value that the distribution can produce. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">result_type</span> <a name="id-1_3_35_5_6_10_1_1_1_6_4-bb"></a><span class="identifier">max</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the largest value that the distribution can produce. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <a name="id-1_3_35_5_6_10_1_1_1_6_5-bb"></a><span class="identifier">probabilities</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns a vector containing the probabilities of each value of the distribution. For example, given</p>
<pre class="programlisting"><span class="identifier">discrete_distribution</span><span class="special">&lt;</span><span class="special">&gt;</span> <span class="identifier">dist</span> <span class="special">=</span> <span class="special">{</span> <span class="number">1</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">5</span> <span class="special">}</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">dist</span><span class="special">.</span><span class="identifier">param</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
</pre>
<p>the vector, p will contain {0.1, 0.4, 0.5}.</p>
<p>If <code class="computeroutput">WeightType</code> is integral, then the weights will be returned unchanged. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <a name="id-1_3_35_5_6_10_1_1_1_6_6-bb"></a><span class="identifier">param</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the parameters of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="id-1_3_35_5_6_10_1_1_1_6_7-bb"></a><span class="identifier">param</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution/param_type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span> param<span class="special">)</span><span class="special">;</span></pre>
<p>Sets the parameters of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="id-1_3_35_5_6_10_1_1_1_6_8-bb"></a><span class="identifier">reset</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Effects: Subsequent uses of the distribution do not depend on values produced by any engine prior to invoking reset. </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.35.5.6.9.3.4.5"></a><h3>
<a name="id-1_3_35_5_6_10_1_1_1_13-bb"></a><code class="computeroutput">discrete_distribution</code> friend functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
  <span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
  <a name="id-1_3_35_5_6_10_1_1_1_13_1-bb"></a><span class="keyword">operator</span><span class="special">&lt;&lt;</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> os<span class="special">,</span> 
             <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> dd<span class="special">)</span><span class="special">;</span></pre>
<p>Writes a distribution to a <code class="computeroutput">std::ostream</code>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
  <span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
  <a name="id-1_3_35_5_6_10_1_1_1_13_2-bb"></a><span class="keyword">operator</span><span class="special">&gt;&gt;</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> is<span class="special">,</span> 
             <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> dd<span class="special">)</span><span class="special">;</span></pre>
<p>Reads a distribution from a <code class="computeroutput">std::istream</code> </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">friend</span> <span class="keyword">bool</span> <a name="id-1_3_35_5_6_10_1_1_1_13_3-bb"></a><span class="keyword">operator</span><span class="special">==</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> lhs<span class="special">,</span> 
                       <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> rhs<span class="special">)</span><span class="special">;</span></pre>
<p>Returns true if the two distributions will return the same sequence of values, when passed equal generators. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">friend</span> <span class="keyword">bool</span> <a name="id-1_3_35_5_6_10_1_1_1_13_4-bb"></a><span class="keyword">operator</span><span class="special">!=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> lhs<span class="special">,</span> 
                       <span class="keyword">const</span> <a class="link" href="discrete_distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> rhs<span class="special">)</span><span class="special">;</span></pre>
<p>Returns true if the two distributions may return different sequences of values, when passed equal generators. </p>
</li>
</ol></div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2000-2005 Jens Maurer<br>Copyright © 2009, 2010 Steven Watanabe<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="discard_block_engine.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_random/reference.html#header.boost.random.discrete_distribution_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="discrete_distribution/param_type.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
